package com.ninetaildemonfox.zdl.socialproject.mvp.ui.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hyphenate.easeui.utils.Preferences;
import com.hyphenate.easeui.utils.map.JSONUtils;
import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.ResponseListener;
import com.kongzue.baseokhttp.util.Parameter;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.v3.MessageDialog;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity.AuthenticationCenterActivity;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity.DetailInterfaceActivity;
import com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity.VipActivity;
import com.ninetaildemonfox.zdl.socialproject.utils.GlideUtils;
import com.ninetaildemonfox.zdl.socialproject.utils.ToastUtil;

import java.util.Map;
import java.util.logging.Logger;

/**
 * 创建人： Nine tails fox
 * 创建时间： 2019/7/19
 * 功能描述: 图片适配器
 * 联系方式：1037438704@qq.com
 *
 * @author NineTailDemonFox
 */

public class ImagViewAdapter2 extends BaseQuickAdapter<Map<String, String>, BaseViewHolder> {

    public ImagViewAdapter2(int imageview) {
        super(imageview);
    }

    @Override
    protected void convert(BaseViewHolder helper, Map<String, String> item) {
        ImageView image_head = helper.itemView.findViewById(R.id.image_head);
        GlideUtils.glideCircle(mContext,item.get("pic"),image_head);
        image_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String getSex = Preferences.getInstance().getString(mContext, "user", "sex");
                String id = item.get("id");
                String sex = item.get("sex");
                if (TextUtils.isEmpty(id) && TextUtils.isEmpty(sex)) {

                } else {
                    if (getSex.equals(sex)) {
                        ToastUtil.show("不能查看同性别的！");
                    } else {
                        panduan(id);
                    }
                }
            }
        });
    }
    private void panduan(String id) {
        AppCompatActivity me = (AppCompatActivity) mContext;
        String getSex = Preferences.getInstance().getString(me, "user", "sex");
        String getIdentification = Preferences.getInstance().getString(me, "user", "identification");
        String getVip = Preferences.getInstance().getString(me, "user", "vip");
        String token = Preferences.getInstance().getString(me, "user", "token");

        //                             是否vip 1否 2是           1未认证 2 已认证
        if (getSex.equals("1")) {
            if (getVip.equals("1")) {
                HttpRequest.POST(mContext, "Index/seeCount"
                        , new Parameter()
                                .add("token", token)
                                .add("cover_member_id", id)
                        , new ResponseListener() {
                            @Override
                            public void onResponse(String response, Exception error) {
                                Map<String, String> map = JSONUtils.parseKeyAndValueToMap(response);
                                Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                                if (data.get("look").equals("1")) {
                                    DetailInterfaceActivity.start(me, id, "1");
                                    return;
                                }
                                int count = Integer.valueOf(data.get("count"));
                                if (count <= 3 && count > 0) {
                                    //立即开通
                                    MessageDialog.show(me, "剩余机会" + data.get("count"), "非会员每天只能查看" + data.get("total") + "位女士", "升级会员", "继续查看")
                                            .setOnOkButtonClickListener(new OnDialogButtonClickListener() {
                                                @Override
                                                public boolean onClick(BaseDialog baseDialog, View v) {
                                                    VipActivity.start(me, "1", 1);
                                                    return false;
                                                }
                                            })
                                            .setOnCancelButtonClickListener(new OnDialogButtonClickListener() {
                                                @Override
                                                public boolean onClick(BaseDialog baseDialog, View v) {
                                                    DetailInterfaceActivity.start(me, id, "1");
                                                    return false;
                                                }
                                            })
                                    ;
                                } else if (count == 0) {
                                    ToastUtil.show("您没有次数了");
                                } else {
                                    DetailInterfaceActivity.start(me, id, "1");
                                }
                            }
                        });
            } else {
                //会员
                DetailInterfaceActivity.start(me, id, "1");
            }
        } else {
            if (getIdentification.equals("1")) {
                HttpRequest.POST(me, "Index/seeCount"
                        , new Parameter()
                                .add("token", token)
                                .add("cover_member_id", id)
                        , new ResponseListener() {
                            @Override
                            public void onResponse(String response, Exception error) {
                                Map<String, String> map = JSONUtils.parseKeyAndValueToMap(response);
                                Map<String, String> data = JSONUtils.parseKeyAndValueToMap(map.get("data"));
                                int count = Integer.valueOf(data.get("count"));
                                if (data.get("look").equals("1")) {
                                    DetailInterfaceActivity.start(me, id, "1");
                                    return;
                                }
                                if (count <= 3 && count > 0) {
                                    //立即开通
                                    MessageDialog.show(me, "剩余机会" + data.get("count"), "未认证每天只能查看"+data.get("total") +"位男士", "去认证", "继续查看")
                                            .setOnOkButtonClickListener(new OnDialogButtonClickListener() {
                                                @Override
                                                public boolean onClick(BaseDialog baseDialog, View v) {
                                                    //去认证
                                                    Intent intent = new Intent(me, AuthenticationCenterActivity.class);
                                                    Bundle bundle = new Bundle();
                                                    bundle.putInt("dataSize", 1);
                                                    intent.putExtras(bundle);
                                                    me.startActivity(intent);
                                                    return false;
                                                }
                                            })
                                            .setOnCancelButtonClickListener(new OnDialogButtonClickListener() {
                                                @Override
                                                public boolean onClick(BaseDialog baseDialog, View v) {
                                                    DetailInterfaceActivity.start(me, id, "1");
                                                    return false;
                                                }
                                            })
                                    ;
                                } else if (count == 0) {
                                    ToastUtil.show("您没有次数了请先认证");
                                    return;
                                } else {
                                    DetailInterfaceActivity.start(me, id, "1");
                                }
                            }
                        });
            } else {
                DetailInterfaceActivity.start(me, id, "1");
            }
        }
    }

}